package com.example.dormitorysystem.controller;


import com.example.dormitorysystem.common.aop.OperationLogAnnotation;
import com.example.dormitorysystem.entity.Auth;
import com.example.dormitorysystem.service.UsersService;
import com.example.dormitorysystem.utils.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-13
 */
@RestController
@RequestMapping("user")
public class UsersController {

    @Resource
    private UsersService usersService;


    @GetMapping("/myinfo")
    @OperationLogAnnotation(operModul = "用户模块", operType = "GetUserInfo", operDesc = "获取个人信息")
    public Response getUserInfo(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = usersService.getUserInfo(request, response);
        return Response.success().data(res);
    }

    @PostMapping("/passwd")
    @OperationLogAnnotation(operModul = "用户模块", operType = "ChangerPassword", operDesc = "修改密码")
    public Response changePasswd(@RequestBody Map<String, Object> input, HttpServletRequest request) {
        usersService.changePasswd(input, request);
        return Response.success();
    }

    @OperationLogAnnotation(operModul = "用户模块", operType = "SelectMyRoom", operDesc = "查询我的宿舍信息")
    @GetMapping("/myroom")
    public Response getMyroomInfo(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = usersService.getMyroomInfo(request, response);
        return Response.success().data(res);
    }


}

